package com.pubinfo.passbook.api.controller.system;

import com.pubinfo.passbook.common.entity.TSubsidiaryInfo;
import com.pubinfo.passbook.common.model.dto.system.SubsidiaryPrivateKey;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.model.vo.base.MyPage;
import com.pubinfo.passbook.common.service.master.TSubsidiaryInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "subsidiary")
@Api(tags = "公司管理")
@Slf4j
public class SubsidiaryInfoController {
  @Autowired
  TSubsidiaryInfoService infoService;
  
  @PostMapping("saveOrUpdate")
  @ApiOperation(value = "新增/修改")
  public JsonResult<Boolean> save(@RequestBody TSubsidiaryInfo info) {
    return JsonResult.success(infoService.saveOrUpdate(info));
  }
  
  @PostMapping("list")
  @ApiOperation(value = "查询列表")
  public JsonResult<MyPage<TSubsidiaryInfo>> list(@RequestBody SubsidiaryPrivateKey privateKey) {
    return JsonResult.success(new MyPage(infoService.listSubsidiaryInfo(privateKey)));
  }
  
  @DeleteMapping("remove/{id}")
  @ApiOperation(value = "删除公司")
  public JsonResult<Boolean> removeFile(@PathVariable("id") String id) {
    return JsonResult.success(infoService.removeById(id));
  }
  
  @PostMapping("removeBatch")
  @ApiOperation(value = "批量删除")
  public JsonResult<Boolean> delete(String[] ids) {
    return JsonResult.success(infoService.removeByIds(CollectionUtils.arrayToList(ids)));
  }
}
